package com.example.administrator.myapplication;

import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.example.administrator.myapplication.util.MyHelper;
import com.example.administrator.myapplication.util.saveqq;

public class MainActivity extends AppCompatActivity {

    private EditText usernameEd;
    private EditText studentIdEd;
    private Button loginBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();

        initEvent();
    }
        private void initView(){
            usernameEd = findViewById(R.id.username_et);
            studentIdEd = findViewById(R.id.student_id_et);
            loginBtn = findViewById(R.id.login_btn);
        } private void initData(){

        String usernameStr =usernameEd.getText().toString()+"";
        String studentIdStr =studentIdEd.getText().toString()+"";
        //实例化SharedPreferences对象
//        SharedPreferences sharedPreferences =getSharedPreferences("data",MODE_PRIVATE);
//        //开启编辑器
//        SharedPreferences.Editor editor=sharedPreferences.edit();
//        //向编辑器存入数据
//        editor.putString("username",usernameStr);
//        editor.putString("studentid",studentIdStr);
//        //提交数据
//        editor.commit();
        saveqq.save(MainActivity.this,"usrname",usernameStr);
        saveqq.save(MainActivity.this,"studentid",studentIdStr);
        MyHelper myHelper =new MyHelper(MainActivity.this);
        myHelper.insert(MainActivity.this,usernameStr,studentIdStr);
    } private void initEvent(){
loginBtn.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        initData();
        Intent intent =new Intent(MainActivity.this,TwoActivity.class);
        startActivity(intent);
    }
});
        }

}
